/*
 * Created on 2006-5-18 0:47:06
 */
package cn.com.sbell.vss.csg.vap;

import org.dom4j.Element;

import cn.com.sbell.vss.VssConstants;
import cn.com.sbell.vss.VssException;
import cn.com.sbell.vss.csg.vap.bean.LocalStorageTask;
import cn.com.sbell.vss.csg.vap.bean.RecordSchedule;
import cn.com.sbell.vss.csg.vsclient.VsClient;
import cn.com.sbell.vss.csg.vsclient.util.PropertiesHolder;

/**
 * @author liang.a.chen
 */
public class GetVsLocalStorageTask extends ProtectedVsCommander {

	protected Element executeCommand(VsClient vsClient, PropertiesHolder holder, Element root) {
		Integer videoId = holder.getIntProperty("videoId");
		if(videoId == null){
			throw new VssException(VssConstants.CODE_REQUIRED,new String[]{"csg.videoId"});
		}
		LocalStorageTask task = vsClient.getVsLocalStorageTask(videoId.intValue());
		root.addElement("videoId").addText(toString(task.getVideoId()));
		root.addElement("recordEnable").addText(toString(task.getRecordEnable()));
		root.addElement("recycleRecEnable").addText(toString(task.getRecycleRecEnable()));
		
		RecordSchedule[] schedule = task.getSchedule();
		for(int i=0;schedule!=null && i<schedule.length;i++){
			if(schedule[i].getStartHour() == schedule[i].getStopHour() && schedule[i].getStartMin() == schedule[i].getStopMin())
				continue;
			Element schelement = root.addElement("schedule");
			schelement.addElement("type").addText(String.valueOf(schedule[i].getRecordType()));
			schelement.addElement("weekday").addText(String.valueOf(schedule[i].getWeekday()));
			schelement.addElement("startHour").addText(String.valueOf(schedule[i].getStartHour()));
			schelement.addElement("startMin").addText(String.valueOf(schedule[i].getStartMin()));
			schelement.addElement("stopHour").addText(String.valueOf(schedule[i].getStopHour()));
			schelement.addElement("stopMin").addText(String.valueOf(schedule[i].getStopMin()));
		}
//		root.addElement("recordPolicy").addText(toString(task.getRecordPolicy()));
//		root.addElement("mjpegFrame").addText(toString(task.getMjpegFrame()));
//		root.addElement("mpeg4Frame").addText(toString(task.getMpeg4Frame()));
//		root.addElement("filenameSuffix").addText(toString(task.getFilenameSuffix()));
//		root.addElement("diskFullThreshold").addText(toString(task.getDiskFullThreshold()));
		
		return root;
	}
}
